<template>
  <div id="dialogLifeUpTime">
    <el-dialog
      class="about-set"
      title="修改批量点赞数量"
      :visible.sync="dialogData.isShow"
      width="420px"
      :before-close="labelHandleClose"
    >
      <div class="form-box">
        <el-form
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          label-width="80px"
          class="demo-ruleForm"
        >
          <el-form-item label="点赞量" prop="num">
            <el-input-number
              v-model="ruleForm.num"
              size="mini"
              controls-position="right"
              :min="1"
            ></el-input-number>
          </el-form-item>
          <el-form-item label="创建时间" prop="date">
            <el-date-picker
              v-model="ruleForm.date"
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" plain @click="cancelLabel">取 消</el-button>
        <el-button
          type="success"
          :loading="loading"
          @click="confirmLabel('ruleForm')"
          >确认</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'dialogLifeUpTime',
  msg: '批量限时加赞',
  props: ['dialogData'],
  data() {
    var valiDate = (rule, value, callback) => {
      if (!value) {
        callback(new Error('时间不能为空'))
      } else {
        let timeInput = new Date(value).getTime()
        let timeNow = new Date().getTime()
        if (timeInput <= timeNow) {
          callback(new Error('限时时间要大于当前时间'))
        } else {
          callback()
        }
      }
    }
    return {
      loading: false,
      ruleForm: {
        num: 1,
        date: ''
      },
      rules: {
        num: [
          { required: true, message: '点赞量不能为空' }
          /* {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'} */
        ],
        date: [{ validator: valiDate, trigger: 'blur' }]
      }
    }
  },
  mounted() {},
  methods: {
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    cancelLabel() {
      // 关闭前清空
      this.loading = false
      this.dialogData.isShow = false
    },
    /* 确认提交 */
    confirmLabel(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('addUpTime', this.ruleForm.num, this.ruleForm.date)
          this.cancelLabel()
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="less">
#dialogLifeUpTime {
  .el-input-number--mini {
    width: 220px;
  }
}
</style>
